home *** CD-ROM | disk | FTP | other *** search
/ Artworks - Keep it Simple 2 / Artworks - Keep it Simple 2.iso / az / launch.dxr / 00025_masterap handlers.ls < prev    next >
Encoding:
Text File  |  1997-07-04  |  8.3 KB  |  325 lines

  1. on loadMasterApp
  2.   global gMasterAppObject
  3.   if objectp(gMasterAppObject) then
  4.     return 1
  5.   end if
  6.   if not objectp(factory("MasterApp")) then
  7.     if not fileExists(the pathName & "MastrApp.dll") then
  8.       alert("loadMasterApp(): can't locate MastrApp.dll")
  9.       return 0
  10.     end if
  11.     openXLib("MastrApp.dll")
  12.   end if
  13.   if not objectp(factory("MasterApp")) then
  14.     alert("loadMasterApp(): can't  use MastrApp.dll")
  15.     return 0
  16.   end if
  17.   if objectp(gMasterAppObject) then
  18.     gMasterAppObject(mdispose)
  19.   end if
  20.   set gMasterAppObject to MasterApp(mnew)
  21.   if not objectp(gMasterAppObject) then
  22.     alert("loadMasterApp(): can't create MasterApp object")
  23.     return 0
  24.   end if
  25.   return 1
  26. end
  27.  
  28. on fileExists theFile
  29.   set fioObj to FileIO(mnew, "read", theFile)
  30.   if objectp(fioObj) then
  31.     fioObj(mdispose)
  32.     return 1
  33.   end if
  34.   return 0
  35. end
  36.  
  37. on nicekillApp theModuleName, theWindowTypeName
  38.   global gMasterAppObject
  39.   if not loadMasterApp() then
  40.     alert("niceKillApp(): no object")
  41.     return 0
  42.   end if
  43.   set tl to gMasterAppObject(mGetTaskList)
  44.   if tl = EMPTY then
  45.     alert("niceKillApp(): empty task list")
  46.     return 0
  47.   end if
  48.   pushDelim(",")
  49.   set tllines to the number of lines in tl
  50.   set targetTasks to 0
  51.   repeat with i = 1 to tllines
  52.     set theTaskLine to line i of tl
  53.     if not (item 1 of theTaskLine = theModuleName) then
  54.       next repeat
  55.     end if
  56.     set targetTasks to targetTasks + 1
  57.     set theTask to integer(item 2 of theTaskLine)
  58.     set wl to gMasterAppObject(mGetTaskWindowList, theTask)
  59.     if wl = "EMTPY" then
  60.       alert("niceKillApp(): target module with no windows")
  61.       popDelim()
  62.       return 0
  63.     end if
  64.     set wllines to the number of lines in wl
  65.     set targetWindows to 0
  66.     repeat with j = 1 to wllines
  67.       set theWindowLine to line j of wl
  68.       set wlItems to the number of items in theWindowLine
  69.       if item wlItems of theWindowLine = theWindowTypeName then
  70.         set targetWindows to targetWindows + 1
  71.         set theWindow to integer(item wlItems - 3 of theWindowLine)
  72.         gMasterAppObject(mWindowToFront, theWindow)
  73.         gMasterAppObject(mCloseWindow, theWindow)
  74.         set giveUpTicks to the ticks + (60 * 5)
  75.         set itQuitItself to 0
  76.         repeat while 1
  77.           if gMasterAppObject(mWindowExists, theWindow) then
  78.             gMasterAppObject(mFeedTimeSlice, theTask)
  79.           else
  80.             set itQuitItself to 1
  81.             exit repeat
  82.           end if
  83.           if the ticks >= giveUpTicks then
  84.             exit repeat
  85.           end if
  86.         end repeat
  87.         if not itQuitItself then
  88.           alert("niceKillApp(): target window didn't close in time")
  89.           popDelim()
  90.           return 0
  91.         end if
  92.       end if
  93.     end repeat
  94.     if targetWindows = 0 then
  95.       alert("niceKillApp(): no target window was found")
  96.       popDelim()
  97.       return 0
  98.     end if
  99.     set giveUpTicks to the ticks + (60 * 5)
  100.     set itQuitItself to 0
  101.     repeat while 1
  102.       if gMasterAppObject(mTaskIsRunning, theTask) then
  103.         gMasterAppObject(mFeedTimeSlice, theTask)
  104.       else
  105.         set itQuitItself to 1
  106.         exit repeat
  107.       end if
  108.       if the ticks >= giveUpTicks then
  109.         exit repeat
  110.       end if
  111.     end repeat
  112.     if not itQuitItself then
  113.       alert("niceKillApp(): target task didn't close in time")
  114.       popDelim()
  115.       return 0
  116.     end if
  117.   end repeat
  118.   if targetTasks = 0 then
  119.     popDelim()
  120.     return 0
  121.   end if
  122.   popDelim()
  123.   return 1
  124. end
  125.  
  126. on waitApp theModuleName, theWindowTypeName
  127.   global gMasterAppObject
  128.   if not loadMasterApp() then
  129.     alert("waitApp(): no object")
  130.     return 0
  131.   end if
  132.   set giveUpTicks to the ticks + (10 * 60)
  133.   set foundIt to 0
  134.   repeat while 1
  135.     gMasterAppObject(mFeedGenericTimeSlice)
  136.     if appRunning(theModuleName, theWindowTypeName) then
  137.       set foundIt to 1
  138.       exit repeat
  139.     end if
  140.     if the ticks > giveUpTicks then
  141.       exit repeat
  142.     end if
  143.   end repeat
  144.   return foundIt
  145. end
  146.  
  147. on appRunning theModuleName, theWindowTypeName, tellWindowID
  148.   global gMasterAppObject
  149.   if not loadMasterApp() then
  150.     alert("appRunning(): no object")
  151.     return 0
  152.   end if
  153.   set tl to gMasterAppObject(mGetTaskList)
  154.   if tl = EMPTY then
  155.     alert("appRunning(): empty task list")
  156.     return 0
  157.   end if
  158.   pushDelim(",")
  159.   set tllines to the number of lines in tl
  160.   repeat with i = 1 to tllines
  161.     set theTaskLine to line i of tl
  162.     if not (item 1 of theTaskLine = theModuleName) then
  163.       next repeat
  164.     end if
  165.     set theTask to integer(item 2 of theTaskLine)
  166.     set wl to gMasterAppObject(mGetTaskWindowList, theTask)
  167.     if wl = "EMTPY" then
  168.       next repeat
  169.     end if
  170.     set wllines to the number of lines in wl
  171.     repeat with j = 1 to wllines
  172.       set theWindowLine to line j of wl
  173.       set wlItems to the number of items in theWindowLine
  174.       if item wlItems of theWindowLine = theWindowTypeName then
  175.         if not voidp(tellWindowID) then
  176.           set valueToReturn to integer(item wlItems - 3 of theWindowLine)
  177.         else
  178.           set valueToReturn to 1
  179.         end if
  180.         popDelim()
  181.         return valueToReturn
  182.       end if
  183.     end repeat
  184.   end repeat
  185.   popDelim()
  186.   return 0
  187. end
  188.  
  189. on getAppWin theModuleName, theWindowTypeName
  190.   return appRunning(theModuleName, theWindowTypeName, "tell me more")
  191. end
  192.  
  193. on pushDelim newItemDelim
  194.   global gDelimList
  195.   if not listp(gDelimList) then
  196.     set gDelimList to []
  197.   end if
  198.   addAt(gDelimList, 1, the itemDelimiter)
  199.   set the itemDelimiter to newItemDelim
  200. end
  201.  
  202. on popDelim
  203.   global gDelimList
  204.   if not listp(gDelimList) then
  205.     set gDelimList to []
  206.   end if
  207.   if count(gDelimList) = 0 then
  208.     return 
  209.   end if
  210.   set the itemDelimiter to getAt(gDelimList, 1)
  211.   deleteAt(gDelimList, 1)
  212. end
  213.  
  214. on rudeKillApp theModuleName
  215.   global gMasterAppObject
  216.   if not loadMasterApp() then
  217.     alert("rudeKillApp(): no object")
  218.     return 0
  219.   end if
  220.   set tl to gMasterAppObject(mGetTaskList)
  221.   if tl = EMPTY then
  222.     alert("rudeKillApp(): empty task list")
  223.     return 0
  224.   end if
  225.   pushDelim(",")
  226.   set tllines to the number of lines in tl
  227.   set targetTasks to 0
  228.   repeat with i = 1 to tllines
  229.     set theTaskLine to line i of tl
  230.     if not (item 1 of theTaskLine = theModuleName) then
  231.       next repeat
  232.     end if
  233.     set targetTasks to targetTasks + 1
  234.     set theTask to integer(item 2 of theTaskLine)
  235.     gMasterAppObject(mRudeQuitTask, theTask, 0)
  236.     set giveUpTicks to the ticks + (60 * 5)
  237.     set itQuitItself to 0
  238.     repeat while 1
  239.       if gMasterAppObject(mTaskIsRunning, theTask) then
  240.         gMasterAppObject(mFeedTimeSlice, theTask)
  241.       else
  242.         set itQuitItself to 1
  243.         exit repeat
  244.       end if
  245.       if the ticks >= giveUpTicks then
  246.         exit repeat
  247.       end if
  248.     end repeat
  249.     if not itQuitItself then
  250.       alert("rudeKillApp(): target task didn't close in time")
  251.       popDelim()
  252.       return 0
  253.     end if
  254.   end repeat
  255.   if targetTasks = 0 then
  256.     alert("rudeKillApp(): no target tasks were found")
  257.     popDelim()
  258.     return 0
  259.   end if
  260.   popDelim()
  261.   return 1
  262. end
  263.  
  264. on bringToFront
  265.   global gMasterAppObject
  266.   if not loadMasterApp() then
  267.     alert("No object")
  268.     return 0
  269.   end if
  270.   set tl to gMasterAppObject(mGetTaskList)
  271.   if tl = EMPTY then
  272.     return 0
  273.   end if
  274.   pushDelim(",")
  275.   set tllines to the number of lines in tl
  276.   set tTaskName to EMPTY
  277.   set taskName to EMPTY
  278.   repeat with i = 1 to tllines
  279.     set theTaskLine to line i of tl
  280.     set tTaskName to item 1 of theTaskLine
  281.     if (tTaskName contains "setup") or (tTaskName contains "install") then
  282.       set taskName to tTaskName
  283.       set theTask to integer(item 2 of theTaskLine)
  284.       exit repeat
  285.     end if
  286.   end repeat
  287.   if taskName = EMPTY then
  288.     return 0
  289.   end if
  290.   set wl to gMasterAppObject(mGetTaskWindowList, theTask)
  291.   if wl = "EMTPY" then
  292.     popDelim()
  293.     return 0
  294.   end if
  295.   set wllines to the number of lines in wl
  296.   set targetWindows to 0
  297.   repeat with j = 1 to wllines
  298.     set theWindowLine to line j of wl
  299.     set wlItems to the number of items in theWindowLine
  300.     if item 1 of theWindowLine = EMPTY then
  301.       next repeat
  302.     end if
  303.     if item wlItems of theWindowLine <> EMPTY then
  304.       set targetWindows to targetWindows + 1
  305.       set theWindow to integer(item wlItems - 3 of theWindowLine)
  306.       gMasterAppObject(mWindowToFront, theWindow)
  307.       exit repeat
  308.     end if
  309.   end repeat
  310.   return 1
  311. end
  312.  
  313. on setpause
  314.   global tickcounter
  315.   set tickcounter to the ticks
  316.   pause()
  317. end
  318.  
  319. on doPause
  320.   global tickcounter
  321.   if the ticks > (tickcounter + 60) then
  322.     continue()
  323.   end if
  324. end
  325.